package com.situ.root.order.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.root.order.model.OrderModel;
import com.situ.root.order.service.impl.OrderServiceImpl;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("order")
public class OrderController {
	
	@Autowired
	private OrderServiceImpl orderServiceImpl;
	
	@RequestMapping(value = "/list",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public List<OrderModel> list(OrderModel model){
		List<OrderModel> res = orderServiceImpl.selectAll(model);
		res = JSONArray.fromObject(res);
		System.out.println("res="+res);
		return res;
	}
	
	@RequestMapping(value = "/del",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String del(Object model) {
		int res = orderServiceImpl.delete(model);
		System.out.println("res="+res);
		return "1";
	}
	
	@RequestMapping(value = "/add",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String add(OrderModel model) {
		int res = orderServiceImpl.insert(model);
		System.out.println("res="+res);
		return "1";
	}
	
	@RequestMapping(value = "/upd",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String upd(OrderModel model) {
		int res = orderServiceImpl.update(model);
		System.out.println("res="+res);
		return "1";
	}
	
	@RequestMapping(value = "/page",method= {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> page(OrderModel model){
		model.setPageOn(true);
		Map<String, Object> map = new HashMap<>();
		map.put("data", orderServiceImpl.selectAll(model));
		map.put("count", orderServiceImpl.selectCount(model));
		System.out.println("map="+map);
		return map;
	}
}
